<template>
  <div class="info_edit_cont">
    <div class="info_list">
      <el-form ref="form" v-bind="getFormProps()">
        <h4 class="plan_title">学情分析</h4>
        <div class="info_show">
          <el-input v-model="form.learningCondition" :placeholder="formTips.learningCondition" :maxlength="500" type="textarea" :rows="6" number-word />
        </div>
        <h4 class="plan_title">学习目标</h4>
        <div class="info_show">
          <el-input v-model="form.learningTarget" :placeholder="formTips.learningTarget" :maxlength="500" type="textarea" :rows="8" number-word />
        </div>
        <h4 class="plan_title">教学措施</h4>
        <div class="info_show">
          <el-input v-model="form.teachingMeasures" :placeholder="formTips.teachingMeasures" :maxlength="500" type="textarea" :rows="8" number-word />
        </div>
      </el-form>
    </div>
    <div class="button-box">
      <el-button @click="goBackList">取 消</el-button>
      <el-button type="primary" @click="handleSubmit" :disabled="form.learningCondition == '' && form.learningTarget == '' && form.teachingMeasures == ''">确 定</el-button>
    </div>
  </div>
</template>
<script>
import {form} from 'utils/mixins' // 引入form mixin
import trainApi from 'api/train'
import { formatTextrea } from 'utils/index'
export default {
  mixins: [form],
  props: {
    teachData: {
      type: Object,
      default: {
        id: '',
        analysis: '',
        target: '',
        measure: ''
      }
    }
  },
  created () {
    if (this.teachData.analysis || this.teachData.target || this.teachData.measure) {
      this.subType = 'put'
    } else {
      this.subType = 'post'
    }
  },
  data () {
    return {
      loading: false, // 必需要返回loading
      subType: 'post',
      formTips: {
        learningCondition: '例如：可以写写该课程年龄段学生的年龄、思想、性格特征等，该课程的特点及要求，学生上该课程的益处，以及对教练的要求等。',
        learningTarget: '例如：\n 1．使学生初步了解运动对身体健康的影响，知道一些保护自身健康的基础常识，教育学生热爱生命、关心健康。\n 2．使学生学会一些基本运动、游戏和韵律活动的方法，培养正确的身体姿态，发展身体素质和基本活动能力。\n 3．使学生感受和体验到参加体育活动的乐趣，具有活泼、乐观、愉快的情绪和积极参加体育活动的态度，培养同伙间友好相处、团结协作的精神。',
        teachingMeasures: '例如：\n 1. 利用游戏培养学生的学习兴趣，提高练习的积极性。\n 2. 利用正确示范和多种诱导方法来促进技能的掌握。\n 3. 利用语言激励学生，提高练习的效果。'
      },
      form: {
        learningCondition: this.teachData.analysis.replace(/<br\s*\/?>/g, '\n'),
        learningTarget: this.teachData.target.replace(/<br\s*\/?>/g, '\n'),
        teachingMeasures: this.teachData.measure.replace(/<br\s*\/?>/g, '\n')
      }
    }
  },
  methods: {
    handleSubmit: function () { // 提交后台数据
      trainApi.editScheme({
        id: this.teachData.id,
        classId: this.$route.query.classid,
        analysis: formatTextrea(this.form.learningCondition),
        target: formatTextrea(this.form.learningTarget),
        measure: formatTextrea(this.form.teachingMeasures)
      }, this.subType).then((res) => {
        this.$emit('cancelEdit')
      })
    },
    goBackList: function () {
      this.$emit('cancelEdit')
    }
  }
}
</script>
<style lang="scss">
.info_edit_cont{
  margin-bottom:80px;
}
</style>
